package com.lzh.others.basejava.Thread_21.bilibili_course_thread;


import com.lzh.others.basejava.Thread_21.utils.SmallTool;

import java.util.concurrent.CompletableFuture;

/**
 * @Description: CompletableFuture:使用练习
 * 任务之间的关系：并发，依赖，互斥
 * 场景1：线程开启，并发；
 * 场景2：线程依赖，
 * 场景3：多个线程同步开启，然后结合，统一返回
 * @Author: LiuZiHao
 * @Date: 2022/12/28 15:25
 */
public class CompletableFuturePrac_03 {
    public static void main(String[] args) {
        SmallTool.printTimeAndThread("小白进入餐厅");
        SmallTool.printTimeAndThread("小白点了 青椒肉丝 + 一碗米饭");
        CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> {
            SmallTool.printTimeAndThread("厨师炒菜");
            SmallTool.sleepMillis(200);
            return "青椒肉丝";
        }).thenCombine(CompletableFuture.supplyAsync(() -> {
            SmallTool.printTimeAndThread("服务员蒸饭");
            SmallTool.sleepMillis(200);
            return "米饭";
        }), (dish, rice) -> {
            SmallTool.printTimeAndThread("服务员打饭");
            SmallTool.sleepMillis(100);
            return String.format("%s + %s 好了", dish, rice);
        });

        SmallTool.printTimeAndThread("小白在打王者");
        SmallTool.printTimeAndThread(String.format("%s,小白开吃", cf1.join()));
    }
}
